
WindDialogModel = function() {
	this.title = "Dialog title"; 
	this.toolbar = WindToolbar.createModel();
}

WindDialogModel.prototype.setView = function (view) {
	this.view = view;
}

WindDialogModel.prototype.getView = function () {
	return this.view;
}

WindDialogModel.prototype.setTitle = function (title) {
	this.title = title;
}

WindDialogModel.prototype.getTitle = function () {
	return this.title;
}

WindDialogModel.prototype.getToolbar = function () {
	return this.toolbar;
}

WindDialogModel.prototype.open = function () {
	this.getView().open();
}

WindDialogModel.prototype.close = function (code, result) {
	this.getView().close(code, result);
}

WindDialogModel.prototype.addError = function (error) {
	this.getView().addError(error);
}

WindDialogModel.prototype.addWarning = function (warning) {
	this.getView().addInfo(warning);
}

WindDialogModel.prototype.addInfo = function (info) {
	this.getView().addInfo(info);
}

WindDialogModel.prototype.clearMessages = function () {
	this.getView().clearMessages();
}

var WindDialog = new Object();

WindDialog.createModel = function() {
	var dialogModel = new WindDialogModel();
	return dialogModel;
}

WindDialog.createView = function(dialogModel) {
	var dialogView = new WindView;
	dialogView.setCssClass("WindDialog");
	
	dialogModel.setView(dialogView);

	var title = new WindView;
	title.setCssClass("WindDialogTitle");
	title.setText(dialogModel.getTitle());
	
	dialogView.addView(title);
	
	var toolbar = new WindView;
	toolbar.setCssClass("WindDialogToolbar");
	dialogView.addView(toolbar);
	
	var _toolbar = WindToolbar.createView(dialogModel.getToolbar());
	toolbar.addView(_toolbar);
	
	var messagesView = new WindMessages.createView();
	dialogView.addView(messagesView);
	
	dialogView.clearMessages = function() {
		messagesView.clearViews();
	}
	
	dialogView.addError = function(error) {
		messagesView.addError(error);
	}
	
	dialogView.addWarning = function(warning) {
		messagesView.addWarning(warning);
	}

	dialogView.addInfo = function(info) {
		messagesView.addInfo(info);
	}

	var body = new WindView;
	body.setCssClass("WindDialogBody");
	
	dialogView.getBody = function() {
		return body;
	}	
	
	var modalLayer = WindDialog.createModalLayerView();
	
	dialogView.open = function() {
		WindWindow.addView(modalLayer);
		WindWindow.addView(dialogView);
	}

	dialogView.close = function(code, result) {
		if(dialogModel.onClose!=null) {
			dialogModel.onClose(code, result);
		}
	
		WindWindow.removeView(dialogView);
		WindWindow.removeView(modalLayer);
	}

	dialogView.addView(body);
	
	return dialogView;
} 

WindDialog.createToolbarButtonView = function() {
	var button = new WindView;
	button.setCssClass("WindDialogToolbarButton");
	return button;
}

WindDialog.createModalLayerView = function() {
	var layer = new WindView;
	layer.setCssClass("WindDialogModalLayer");
	layer.setFullscreen(true);
	return layer;
}

